import MyRequest from './request';
import { BASE_URL, TIME_OUT } from './request/config';
import { localCache } from '@/utils';
import { ElMessage } from 'element-plus';

export default new MyRequest({
  baseURL: BASE_URL,
  timeout: TIME_OUT,
  interceptors: {
    requestInterceptor: function (config) {
      const token = localCache.getCache('token');
      if (token) {
        config.headers.Authorization = `Bearer ${token}`;
      }
      return config;
    },

    responseInterceptor: function (res) {
      return res;
    },

    responseInterceptorCatch: function () {
      ElMessage.error('接口错误');
    },
  },
});
